package com.lul15834.orderfood.activity.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;
import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.user.fragment.UserFinishFragment;
import com.lul15834.orderfood.activity.user.fragment.UserHomeFragment;
import com.lul15834.orderfood.activity.user.fragment.UserMyFragment;
import com.lul15834.orderfood.activity.user.fragment.UserNoFinishFragment;

public class ManageUser extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_manage_user);
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        //实现第一次访问加载的界面
        Intent intent=getIntent();
        String sta=intent.getStringExtra("sta");
        if(sta==null||sta.isEmpty()){
            transaction.replace(R.id.user_manager_frame,new UserHomeFragment());
            transaction.commit();
        }else {
            transaction.replace(R.id.user_manager_frame,new UserMyFragment());
            transaction.commit();
        }
        BottomNavigationView bottomNavigationView= findViewById(R.id.user_manager_bottom_menu);
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                FragmentManager fragmentManager1=getSupportFragmentManager();
                FragmentTransaction transaction1=fragmentManager1.beginTransaction();
                int id=item.getItemId();
                if (id==R.id.user_manager_bottom_menu_home){
                    transaction1.replace(R.id.user_manager_frame,new UserHomeFragment());
                }
                //打开一个新的界面
                if (id==R.id.user_manager_bottom_menu_dsh){
                    //跳转到新的界面
                    transaction1.replace(R.id.user_manager_frame,new UserNoFinishFragment());
                }
                if (id==R.id.user_manager_bottom_menu_my){
                    transaction1.replace(R.id.user_manager_frame,new UserMyFragment());
                }
                transaction1.commit();
                return true;
            }
        });
    }
    public void showOrder(){
        FragmentManager fragmentManager=this.getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.user_manager_frame,new UserFinishFragment());
        transaction.commit();
    }
    public void showMy(){
        FragmentManager fragmentManager=this.getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.user_manager_frame,new UserMyFragment());
        transaction.commit();
    }
}